package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.commons.entity.Blog;
import com.gzxw.mogublog.commons.entity.Comment;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.CommentService;
import com.gzxw.mogublog.xo.vo.CommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/getList")
    public R getList(@RequestBody CommentVO commentVO) {

        IPage<Comment> pageList = commentService.getPageList(commentVO);
        Map<String ,Object> result = new HashMap<>();
        List<Comment> records = pageList.getRecords();
        long total = pageList.getTotal();
        long size = pageList.getSize();
        long current = pageList.getCurrent();
        result.put("records",records);
        result.put("total",total);
        result.put("size",size);
        result.put("current",current);

        return R.success("200",result);
    }


    @PostMapping("/add")
    public R add(@RequestBody CommentVO commentVO) {


        String message = commentService.addComment(commentVO);

        return R.success("200",message);
    }


    @PostMapping("/edit")
    public R edit(@RequestBody CommentVO commentVO) {


        String message = commentService.editComment(commentVO);

        return R.success("200",message);
    }


    @PostMapping("/delete")
    public R delete(@RequestBody CommentVO commentVO) {

        String message = commentService.deleteComment(commentVO);

        return R.success("200",message);
    }


    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<CommentVO> commentVoList) {

        String message =  commentService.deleteBatchComment(commentVoList);

        return R.success("200",message);
    }


}
